<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>冒泡排序</title>
</head>
<body>
    
    <script>
    
        {
            // 冒泡排序

            let ary = [10,14,18,20,12,16];

            Array.prototype.bubbleSort = function () {
                for(let i=0;i<this.length-1;i++){
                    for(let j=this.length-1-i;j<this.length;j++){
                        if(this[j]>this[j+1]){
                            [this[j],this[j+1]] = [this[j+1],this[j]];
                        }
                    }
                }
                return this;
            }

            console.log(ary.bubbleSort());

        }
    
    </script>

</body>
</html>